<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增部门')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-dept-add">
        <input id="flagint" name="flagint" type="hidden" value="0"/>
        <input id="fkint" name="fkint" type="hidden" value=""/>
        <input id="useflag" name="useflag" type="hidden" value="1"/>
        <!--        <input id="treeId" name="codepk" type="hidden" th:value="${sort.codepk}"/>-->
        <div class="col-sm-12">
            <div class="form-group">
                <label class="col-sm-2 control-label">上级内容分类：</label>
                <div class="col-sm-10">
                    <div class="input-group">
                        <input style="margin-left: -10px" class="form-control" type="text" onclick="selectSortTree()" id="treeName" readonly="true"
                               th:value="${sort.sortname}">
                        <input type="hidden" name="codeparent" th:value="${sort.codepk}">
                        <span style="margin-left: -20px" class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">分类编号：</label>
                    <div class="col-sm-6">
                        <input name="codepk" id="codepk" oninput="self()" placeholder="请输入内容ID" class="form-control"
                               type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">分类名称：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="sortname" id="sortname" required type="text" placeholder="内容"
                                   class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">排序值：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="ordnum" required type="text" placeholder="排序值" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "system/content";

    $("#form-dept-add").validate({
        onkeyup: false,
        rules: {
            sortname: {
                remote: {
                    url: prefix + "/checkSortNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "codepk": function () {
                            return $("input[name='codepk']").val();
                        },
                        "sortname": function () {
                            return $.common.trim($("#sortname").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            order_num: {
                digits: true
            },
            email: {
                email: true,
            },
            phone: {
                isPhone: true,
            },
        },
        messages: {
            "sortname": {
                remote: "内容已存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            console.log($('#form-dept-add').serialize());
            $.operate.save(prefix + "/contentSortAddJson", $('#form-dept-add').serialize());
        }
    }

    /*部门管理-新增-选择父部门树*/
    function selectSortTree() {
        var options = {
            title: '内容分类选择',
            width: "380",
            url: prefix + "/selectSortTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }

    function DropChgSendTextOnly(e, acpId) {
        document.getElementById(acpId).value = e.options[e.selectedIndex].text;
    }

    function self() {
        $("#noSelf").val($("#codepk").val())
    }
</script>
</body>
</html>
